package com.apes.scm.masterdata.stock.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.scm.masterdata.area.model.Area;
import com.apes.scm.masterdata.area.model.Country;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;

/**
 * 功能：物理仓库
 *
 * @author HuJianLin
 * @create 2018-03-14 9:25
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = PhyDepot.CONST_TABLE_NAME)
public class PhyDepot extends Model {
    public static final String CONST_TABLE_NAME = "mas_phy_depot";

    @Id
    @Column(name = "id")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "物理仓库")
    @Comment("仓库编码")
    private String id;

    @Column(name = "name", length = 120)
    @Comment("仓库名称")
    private String name; //仓库名称

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "country_id", referencedColumnName = "id")
    @Comment("国家")
    private Country country; //国家

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "province_id", referencedColumnName = "id")
    @Comment("省份")
    private Area province; //省份

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "city_id", referencedColumnName = "id")
    @Comment("城市")
    private Area city; //城市

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "county_id", referencedColumnName = "id")
    @Comment("区县")
    private Area county; //区县

    @Column(name = "address", length = 500)
    @Comment("地址")
    private String address; //地址

    @Column(name = "area", nullable = false)
    @Comment("面积")
    private double area = 0; //面积

    @Column(name = "phone", length = 60)
    @Comment("电话")
    private String phone;  //电话

    @Column(name = "longitude", nullable = false)
    @Comment("经度")
    private double longitude = 0.0;  //经度

    @Column(name = "latitude", nullable = false)
    @Comment("纬度")
    private double latitude = 0.0;  //纬度


    @Column(name = "ORIGIN", length = 20)
    @Comment("外部ID")
    private String origin; //外部ID
}
